export function phone(required = true, value = '', options = {}) {
    var res = {
        validate: {
            presence: required,
            numericality: {
                greaterThan: -1
            },
            length: {
                is: 11
            }
        },
        attr: {
            value: value
        }
    };
    return Object.assign(res, options);
};

export function linkEqualMain(linkfieldkey, value = '', options = {}) {
    var res = {
        validate: {
            presence: true
        },
        onValidate: function (newval, oldval, constraint, form) {
            if (form.element[linkfieldkey] && 
                form.element[linkfieldkey].element && 
                form.element[linkfieldkey].element.classList.contains("is-dirty")) {
                form.validateField(linkfieldkey);
            }
        },
        attr: {
            value: value
        }
    };
    return Object.assign(res, options);
};

export function linkEqualSub (linkfieldkey, value = '', options = {}) {
    var res =  {
        validate: {
            presence: true
        },
        onValidate: function (newval, oldval, constraint, form) {
            if (form.data[linkfieldkey].value == newval) {
                return false;
            }
            return [{
            }];
        },
        attr: {
            value: value
        }
    };
    return Object.assign(res, options);
};
